#include "pool_allocator.h"
#include "ss_allocator.h"
#include <vector>
#include <iostream>
#include <algorithm>
//#include "timer.h"
#include <string>
#include <ctime>
using namespace std;

const int size = 1000;

struct foo
{
  foo(const string &s = "Hello world", int i = 0):s_(s), i_(i){}
  string s_;
  int i_;
  bool operator <(const foo& other)const{return i_<other.i_;}
};

foo generator()
{
  return foo("Hello world", rand());
}

int main() 
{
  cout.precision(10); 
  cout<<"***Tests with <vector>***"<<endl;

  clock_t t_base, t_end;

  t_base = clock();
  vector<foo, pool_allocator<foo> > pool_vector(size);
  t_end = clock() - t_base;
  cout << "Pool vector construction " << t_end/(double)CLOCKS_PER_SEC << endl;


  t_base = clock();
  vector<foo, ss_allocator<foo> > ss_vector(size);
  t_end = clock() - t_base;
  cout << "SS vector construction " << t_end/(double)CLOCKS_PER_SEC << endl;

  t_base = clock();
  vector<foo> default_vector(size);
  t_end = clock() - t_base;
  cout << "Default vector construction " << t_end/(double)CLOCKS_PER_SEC << endl;


  generate(pool_vector.begin(), pool_vector.end(), generator);
  copy(pool_vector.begin(), pool_vector.end(), default_vector.begin());
  copy(pool_vector.begin(), pool_vector.end(), ss_vector.begin());

  t_base = clock();
  sort(pool_vector.begin(), pool_vector.end());
  t_end = clock() - t_base;
  cout << "Pool vector sort " << t_end/(double)CLOCKS_PER_SEC << endl;

  t_base = clock();
  sort(ss_vector.begin(), ss_vector.end());
  t_end = clock() - t_base;
  cout << "SS vector sort " << t_end/(double)CLOCKS_PER_SEC << endl;

  t_base = clock();
  sort(default_vector.begin(), default_vector.end());
  t_end = clock() - t_base;
  cout << "Default vector sort " << t_end/(double)CLOCKS_PER_SEC << endl;

  cout<<"***Tests with <list>***"<<endl;
  t_base = clock();
  list<foo, pool_allocator<foo> > pool_list(size);
  t_end = clock() - t_base;
  cout << "Pool list construction " << t_end/(double)CLOCKS_PER_SEC << endl;

  t_base = clock();
  list<foo, ss_allocator<foo> > ss_list(size);
  t_end = clock() - t_base;
  cout << "SS list construction " << t_end/(double)CLOCKS_PER_SEC << endl;

  t_base = clock();
  list<foo> default_list(size);
  t_end = clock() - t_base;
  cout << "Default list construction " << t_end/(double)CLOCKS_PER_SEC << endl;

  generate(pool_list.begin(), pool_list.end(), generator);
  copy(pool_list.begin(), pool_list.end(), default_list.begin());
  copy(pool_list.begin(), pool_list.end(), ss_list.begin());

  t_base = clock();
  pool_list.sort();
  t_end = clock() - t_base;
  cout << "Pool list sort " << t_end/(double)CLOCKS_PER_SEC << endl;

  t_base = clock();
  ss_list.sort();
  t_end = clock() - t_base;
  cout << "SS list sort " << t_end/(double)CLOCKS_PER_SEC << endl;

  t_base = clock();
  default_list.sort();
  t_end = clock() - t_base;
  cout << "Default list sort " << t_end/(double)CLOCKS_PER_SEC << endl;

  cout<<"Press <Enter>..."<<endl;
  char c;
  cin.getline(&c, 1);

  return 0;
}


